﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;

namespace Facebook
{
    public static class MD5Extensions
    {
        public static String ComputeHashString(this MD5 md5, String input)
        {
            return MD5Extensions.ComputeHashString(md5, input, Encoding.UTF8);
        }

        public static String ComputeHashString(this MD5 md5, String input, Encoding encoding)
        {            
            Byte[] inputBytes = encoding.GetBytes(input);
            var hashBuilder = new StringBuilder();
            List<Byte> hashBytes = md5.ComputeHash(inputBytes).ToList();
            hashBytes.ForEach(hashByte => hashBuilder.AppendFormat("{0:x2}", hashByte));
            return hashBuilder.ToString();            
        }
    }
}